﻿using System;
using Bricks.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace Bricks.EnterpriseLibrary.Caching
{

    /// <summary>
    /// 
    /// </summary>
    public class CacheManagerFacade : CacheFacadeBase<ICacheManager>, ICacheManagerFacade
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="cacheManager"></param>
        public CacheManagerFacade(ICacheManager cacheManager) :
            base(() => cacheManager)
        {
            if (cacheManager == null)
            {
                throw new ArgumentNullException("cacheManager");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public override void Add(string key, object value)
        {
            Execute(cacheManager => cacheManager.Add(key, value));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override bool Contains(string key)
        {
            return Execute<bool>(cacheManager => cacheManager.Contains(key));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override object Get(string key)
        {
            return Execute<object>(cacheManager => cacheManager.GetData(key));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public override void Remove(string key)
        {
            Execute(cacheManager => cacheManager.Remove(key));
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Flush()
        {
            Execute(cacheManager => cacheManager.Flush());
        }
    }
}
